package com.xydtech.ecard.config.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.config.domain.EcardServeModuleConfig;
import com.xydtech.ecard.config.service.IEcardServeModuleConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务模块配置Controller
 *
 * @author JHON
 * @date 2022-06-23
 */
@Controller
@RequestMapping("/ecard/config/serveModuleConfig")
public class EcardServeModuleConfigController extends BaseController {
    private String prefix = "ecard/config/serveModuleConfig";

    @Autowired
    private IEcardServeModuleConfigService ecardServeModuleConfigService;

    @RequiresPermissions("ecard:config:serveModuleConfig:view")
    @GetMapping()
    public String serveModuleConfig() {
        return prefix + "/serveModuleConfig";
    }

    /**
     * 查询服务模块配置列表
     */
    @RequiresPermissions("ecard:config:serveModuleConfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardServeModuleConfig ecardServeModuleConfig) {
        startPage();
        List<EcardServeModuleConfig> list = ecardServeModuleConfigService.selectEcardServeModuleConfigList(ecardServeModuleConfig);
        return getDataTable(list);
    }

    /**
     * 导出服务模块配置列表
     */
    @RequiresPermissions("ecard:config:serveModuleConfig:export")
    @Log(title = "服务模块配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardServeModuleConfig ecardServeModuleConfig) {
        List<EcardServeModuleConfig> list = ecardServeModuleConfigService.selectEcardServeModuleConfigList(ecardServeModuleConfig);
        ExcelUtil<EcardServeModuleConfig> util = new ExcelUtil<EcardServeModuleConfig>(EcardServeModuleConfig.class);
        return util.exportExcel(list, "服务模块配置数据");
    }

    /**
     * 新增服务模块配置
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存服务模块配置
     */
    @RequiresPermissions("ecard:config:serveModuleConfig:add")
    @Log(title = "服务模块配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardServeModuleConfig ecardServeModuleConfig) {
        return toAjax(ecardServeModuleConfigService.insertEcardServeModuleConfig(ecardServeModuleConfig));
    }

    /**
     * 修改服务模块配置
     */
    @GetMapping("/edit/{moduleId}")
    public String edit(@PathVariable("moduleId") Long moduleId, ModelMap mmap) {
        EcardServeModuleConfig ecardServeModuleConfig = ecardServeModuleConfigService.selectEcardServeModuleConfigByModuleId(moduleId);
        mmap.put("ecardServeModuleConfig", ecardServeModuleConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务模块配置
     */
    @RequiresPermissions("ecard:config:serveModuleConfig:edit")
    @Log(title = "服务模块配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardServeModuleConfig ecardServeModuleConfig) {
        return toAjax(ecardServeModuleConfigService.updateEcardServeModuleConfig(ecardServeModuleConfig));
    }

    /**
     * 删除服务模块配置
     */
    @RequiresPermissions("ecard:config:serveModuleConfig:remove")
    @Log(title = "服务模块配置", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ecardServeModuleConfigService.deleteEcardServeModuleConfigByModuleIds(ids));
    }
}
